<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <script src="http://api.map.baidu.com/api?v=2.0&ak=W1a6ywZFkybedSCHadpRbkz4w5HYfG4R" type="text/javascript" charset="utf-8"></script>
    <style>
        #updateArea{
            position:absolute;
            left:270px;
            top: 230px;
        }
        #updateArea2{
            position:absolute;
            left:345px;
            top: 280px;
        }
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            position: relative;
        }


        #allmap {
            width: 100%;
            height: 700px;
        }
        #r-result{
            position: absolute;
            left: 0;
            top: 100px;
            background: #000;
            color: #fff;
        }
    </style>
</head>
<body>
<form class="layui-form" lay-filter="example">
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">预录单号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="planOdd" id="planOdd" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" id="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone" id="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">下单时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="time" id="orderTime" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>


        <!--弹出层表头-->
        <script type="text/html" id="popupsToolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加一行</button>
            </div>
        </script>

        <script type="text/html" id="popupsToolbarDemoFee">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="addFeeRow">添加一行</button>
            </div>
        </script>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="yet" id="yet">已接获</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="not">异常</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="update">修改</a>
        </script>

        <!--弹出层操作列-->
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

        <script type="text/html" id="barDemoFee">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delFee">删除</a>
        </script>

    </div>
</div>
</form>
<!--修改-->
<form style="display:none" id="addPlanOrder" class="layui-form" lay-filter="example">
<div>
    <div class="layui-form">
        <p style="height: 20px"></p>
        <div class="layui-form-item">
            <label class="layui-form-label">预录单号:</label>
            <div class="layui-input-inline">
                <input type="text" id="planOrderOdd" lay-verify="title" autocomplete="off" class="layui-input" readonly="true">
            </div>
            <label class="layui-form-label">受理日期:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="plandate" placeholder="yyyy-MM-dd HH:mm:ss" readonly="true">
            </div>
            <label class="layui-form-label">交付方式:</label>
            <div class="layui-input-inline">
                <select  id="delivery" lay-filter="delivery">
                    <option value="1">自提</option>
                    <option value="0">送货</option>
                </select>
            </div>
        </div>
        <hr/>
        <div class="layui-form-item" id="area-picker">
            <p style="height: 10px"></p>
            <div class="layui-form-label required">下单地址:</div>
            <div class="layui-input-inline" style="width: 200px;">
                <select id="province" class="province-selector" data-value="广东省" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select id="city" class="city-selector" data-value="深圳市" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select id="county" class="county-selector" data-value="龙岗区" lay-filter="county-1">
                    <option value="">请选择区</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发货人:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="consigner">
            </div>
            <label class="layui-form-label">联系电话:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="consignerPhone">
            </div>

            <label class="layui-form-label">详细地址:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="detailedArea">
            </div>
        </div>
        <hr/>
        <p style="height: 10px"></p>
        <div class="layui-form-item">
            <label class="layui-form-label">收货人<span style="color: red">*</span>&nbsp;:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="addressName" alt="123">
            </div>
            <label class="layui-form-label">联系电话<span style="color: red">&nbsp;*</span>:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="tel">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">收货地址:<span style="color: red">*</span>&nbsp;:</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="address" style="width:280px;" readonly="true">
            </div>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" id="updateArea">....</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" id="updateArea2">....</button>
        </div>

    </div>
</div>
</form>
<!--收货地址DIV-->
<div id="userAddress" style="display:none">
    <table class="layui-hide" id="addressTableFilter" lay-filter="addressTableFilter"></table>

</div>
<!--百度地图Div-->
<div id="map" style="display:none">
    <div id="allmap"></div>
    <div id="r-result">请输入:<input type="text" id="suggestId" size="20" value="百度" style="width:150px;" /></div>
    <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
    <script type="text/javascript">

        var map = new BMap.Map("allmap");
        map.centerAndZoom("郑州", 15); // 初始化地图,设置中心点坐标和地图级别
        map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
        map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
        function G(id) {
            return document.getElementById(id);
        }
        var ac = new BMap.Autocomplete( //建立一个自动完成的对象
            {
                "input": "suggestId",
                "location": map
            });

        ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if(e.fromitem.index > -1) {
                value = _value.province + _value.city + _value.district + _value.street + _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

            value = "";
            if(e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province + _value.city + _value.district + _value.street + _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            G("searchResultPanel").innerHTML = str;
        });

        var myValue;
        ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
            G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

            setPlace();
        });

        function setPlace() {
            map.clearOverlays(); //清除地图上所有覆盖物
            function myFun() {
                var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
                map.centerAndZoom(pp, 18);
                map.addOverlay(new BMap.Marker(pp)); //添加标注
            }
            var local = new BMap.LocalSearch(map, { //智能搜索
                onSearchComplete: myFun
            });
        }


        //获取当前位置
        var geolocation = new BMap.Geolocation();
        //alert(geolocation);
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                mk = new BMap.Marker(r.point);
                getAddress(r.point);
            }else {
                alert('failed'+this.getStatus());
            }
        });
        //获取地址信息，设置地址label
        function getAddress(point){
            var gc = new BMap.Geocoder();
            gc.getLocation(point, function(rs){
                var addComp = rs.addressComponents;
                var address =  addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
            });

        }
    </script>
</div>

<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var tableDate = [{'cargo':'','backType':0,'number':'0','weight':'0','volume':0,'value':0}];
    var tableDate2 = [{'feeName':'0','taxRate':0,'amountReceivable':'0','taxes':'0','income':0}];
    var packSel = null;
    var feeSel = null;

    //配置插件目录
    layui.config({
        base: '/static/admin/js/lay-module/layarea/'
        , version: '1.0'
    });

    layui.use(['table', 'layer', 'element', 'jquery', 'form','laydate','layarea'], function (table, layer, element, $, form,laydate){
        var layarea = layui.layarea;
        form.on('select(area)', function (data) {
           $.ajax({
                type:"get",
                url:'/admin/planOrder/getExpressGrant',
                data:{
                    siteID:$("#area option:selected").val()
                },
               dataType:'Json',
               success: function (data) {
                    //console.log(data.data);
                   if(data.data == 1){
                       layer.open({
                           title: '提示'
                           ,icon:5
                           ,content: '使用完了，请联系管理员申请面单'
                       });
                   }else if (data.data == 0) {
                       layer.open({
                           title: '提示'
                           ,icon:5
                           ,content: '请联系管理员申请面单'
                       });
                   }else{
                       $("#courierOdd").val(data.data);
                   }


               }
            });

        });
        //常规用法
        laydate.render({
            elem: '#plandate'
            ,type: 'datetime'
        });

        table.render({
            elem: '#currentTableId',
            url: '/admin/planOrder/findAllPlanOrder',
            toolbar: '#toolbarDemo',
            defaultToolbar: [''],
            cols: [
                [
                    {type: "checkbox", width: 50,fixed: 'left'},
                    {field: 'recordedNumber', width: 240, title: '预录单号', sort: true,align: "center",fixed: 'left',
                        templet:function (res) {

                            if(res.orderStart == '2'){
                                return '<span style="background: red">'+res.recordedNumber+'</span>'
                            }else{
                                return '<span>'+res.recordedNumber+'</span>'
                            }
                        }
                    },
                    {field: 'orderStart', width: 100, title: '预录单状态',align: "center",
                        templet:function (obj) {
                            if(obj.orderStart == "1"){
                                $("#yet").css("display","none");
                                return '<span style="color: green">已接货</span>'
                            }else if(obj.orderStart == "3"){
                                return '<span style="color: red">已取消</span>'
                            }else{
                                return '<span>未接货</span>'
                            }
                        }
                        ,fixed: 'left'},
                    {field: 'planOrderTime', title: '下单时间', width: 180,align: "center"},
                    {field: 'sendName', width: 100, title: '寄件人',align: "center"},
                    {field: 'sendPhone', width: 120, title: '寄件人联系方式',align: "center"},
                    {field: 'sendArea', title: '下单地址', width: 250,align: "center"},
                    {field: 'putName', width: 90, title: '收货人',align: "center"},
                    {field: 'putPhone', width: 180, title: '收货人电话',align: "center"},
                    {field: 'putArea', width: 180, title: '收货地区',align: "center"},
                    {field: 'putAddress', width: 150, title: '详细地址',align: "center"},
                    {field: 'createTime', width: 180, title: '创建时间',align: "center"},
                    {field: 'empName', width: 120, title: '操作人',align: "center"},
                    {field: 'updateTime', width: 180, title: '修改时间',align: "center"},
                    {field: 'caozuo', width: 240, title:'操作',align: "center",fixed: 'right',
                        templet:function (res) {
                            if(res.orderStart == '1' || res.orderStart == '2' || res.orderStart == '3'){
                                return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>'
                            }else{
                                    return '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="yet" id="yet">已接获</a>\n' +
                                        '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="not">异常</a>\n' +
                                        '<a class="layui-btn layui-btn-xs data-count-delete" lay-event="update">修改</a>'
                                        +'<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>'
                            }

                        }
                    }
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1 //当前页码数
                }
                , where: {
                    planOdd:$("#planOdd").val(),
                    orderTime:$("#orderTime").val(),
                    phone:$("#phone").val(),
                    username:$("#username").val()
                }
            }, 'data');

            return false;
        });

        table.on('toolbar(popups1)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var dataBak = [];
                    var tableBak = table.cache.popups1;

                    for(var i = 0; i < tableBak.length; i++){
                        dataBak.push(tableBak[i]);
                    }
                    var data1={'cargo':'','backType':'0','number':'0','weight':'0','volume':0,'value':0};
                    dataBak.push(data1);
                    table.reload('popups1',{data : dataBak});
                    break;

            }
        });
        table.on('toolbar(popups2)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            if(obj.event === 'addFeeRow'){
                var dataBak = [];
                var tableBak = table.cache.popups2;
                for(var i = 0; i < tableBak.length; i++){
                    dataBak.push(tableBak[i]);
                }
                var data1={'feeName':'0','taxRate':'','amountReceivable':'0','taxes':'0','income':0};
                dataBak.push(data1);
                table.reload('popups2',{data : dataBak});
            }
        });


        //操作列
        table.on('tool(popups1)',function (obj) {
            var id = obj.data.id;
            if (obj.event === 'del'){
                obj.del();
                var tableData = table.cache['popups1'];

                table.reload('test',{data : tableData});
            }
        });

        table.on('tool(popups2)',function (obj) {
            var id = obj.data.id;
            if (obj.event === 'delFee'){
                obj.del();
                var tableData = table.cache['popups2'];
                table.reload('test',{data : tableData});
            }
        });
        //操作列
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'yet') {

                // 监听修改下拉框update到表格中
                form.on('select(stateSelect)', function (data) {
                    var elem = $(data.elem);
                    var trElem = elem.parents('tr');
                    var tableData = table.cache['popups1'];
                    tableData[trElem.data('index')].backType = data.value;
                    $("#selectTest").val(data.value);
                    form.render('select');
                });

                form.on('select(stateSelectFee)', function (data) {
                    var elem = $(data.elem);
                    var trElem = elem.parents('tr');
                    var tableData = table.cache['popups2'];
                    alert(data.value);
                    tableData[trElem.data('index')].feeName = data.value;
                    $("#selectTestFee").val(data.value);
                    form.render('select');
                });

                form.on('select(stateSelectTaxRate)', function (data) {
                    var elem = $(data.elem);
                    var trElem = elem.parents('tr');
                    var tableData = table.cache['popups2'];
                    tableData[trElem.data('index')].taxRate = data.value;
                    $("#stateSelectTaxRate").val(data.value);
                    form.render('select');
                });
                //监听单元格编辑
                table.on('edit(popups1)', function(obj){
                    //alert(obj);
                    //获取表格里的所有数据
                    var tableData = table.cache['popups1'];
                    //console.log( obj);
                    table.reload('popups1',{data : tableData});
                });

                //监听单元格编辑
                table.on('edit(popups2)', function(obj){
                    var value = obj.value;//修改后的数据
                    var field = obj.field;//修改的字段名
                    var data = obj.data;//修改的当行数据

                    //console.log(data);

                    if(field ==="amountReceivable"){
                        obj.update({
                            taxes:data.taxRate * value,
                            income:value - data.taxRate * value
                        });
                    }

                    //console.log(obj.tr);taxes
                    var elem = $(data.elem);
                    var trElem = elem.parents('tr');
                    var tableData = table.cache['popups2'];
                    //tableData[trElem.data('index')].taxes = obj.value;
                    console.log(tableData);
                    //获取表格里的所有数据
                    //var tableData = table.cache['popups2'];
                    //console.log( obj);
                    table.reload('popups2',{data : tableData});
                    var select = 'dd[lay-value=' + obj.data.feeName + ']';
                    $('#selectTestFee').siblings("div.layui-form-select").find('dl').find(select).click();
                });

                /*货品明细*/
                var tableIns = table.render({
                    elem: '#popups1',
                    wdith:'1000px',
                    data: tableDate,
                    defaultToolbar:[''],
                    toolbar: '#popupsToolbarDemo',
                    done: function (res, curr, count) {
                        var tableElem = this.elem.next('.layui-table-view');
                        count || tableElem.find('.layui-table-header').css('overflow', 'auto');
                        layui.each(tableElem.find('select[name="status"]'), function (index, item) {
                            var elem = $(item);
                            elem.val(elem.data('state')).parents('.layui-table-body, .layui-table-box, .layui-table-cell').css('overflow', 'visible');
                        });
                        form.render();
                    },
                    size: 'lg',
                    cols: [
                        [ //表头
                            {field: 'cargo', width: 140, title: '品名', sort: true,align: "center",edit: 'text',totalRowText: '合计'},
                            {
                                field: 'backType',
                                title: '包装',
                                align: 'center',
                                width: 180,
                                templet:function (d) {
                                    if (packSel == null) {
                                        $.ajax({
                                            url: '/planOrder/getBackType',
                                            dataType: 'json',
                                            type: 'get',
                                            async: false,
                                            success: function (data) {
                                                packSel = '<select name="status" lay-filter="stateSelect" lay-verify="required" id="selectTest" data-state="' + d.status + '" data-value="' + d.id + '" >';
                                                $.each(data, function (index, val) {

                                                    packSel = packSel + '<option value="'+val.orderPackId+'">' + val.orderPackWay + '</option>'
                                                });
                                                packSel = packSel + '   </select>';
                                            },
                                            error: function (msg) {
                                            }
                                        });
                                        return packSel;
                                    }else{
                                        return packSel;
                                    }
                                }
                            },
                            {field: 'number', width: 140, title: '数量',align: "center", edit: 'text',totalRow: true},
                            {field: 'weight', width: 140, title: '重量', align: "center", edit: 'text',totalRow: true},
                            {field: 'volume', width: 130, title: '体积',align: "center", edit: 'text',totalRow: true},
                            {field: 'value', width: 140, title: '货值',align: "center", edit: 'text',totalRow: true},
                            {title: '操作', width: 115, toolbar: '#barDemo', align: "center"}
                        ]
                    ]
                });
                /*费用明细*/
                table.render({
                    elem: '#popups2',
                    wdith:'1000px',
                    data: tableDate2,
                    size: 'lg',
                    defaultToolbar:[''],
                    toolbar: '#popupsToolbarDemoFee',
                    done: function (res, curr, count) {
                        var tableElem = this.elem.next('.layui-table-view');
                        count || tableElem.find('.layui-table-header').css('overflow', 'auto');
                        layui.each(tableElem.find('select[name="statusFee"]'), function (index, item) {
                            var elem = $(item);
                            elem.val(elem.data('state')).parents('.layui-table-body, .layui-table-box, .layui-table-cell').css('overflow', 'visible');
                        });
                        layui.each(tableElem.find('select[name="statusTaxRate"]'), function (index, item) {
                            var elem = $(item);
                            /*console.log(item);
                            console.log(elem);*/
                            elem.val(elem.data('state')).parents('.layui-table-body, .layui-table-box, .layui-table-cell').css('overflow', 'visible');

                        });
                        form.render();
                    },
                    cols:[
                        [
                            {field:'feeName',title:'费用名称',align: 'center', width: 170,
                                templet:function (d) {
                                    if (feeSel == null) {
                                        $.ajax({
                                            url: '/planOrder/getFeeType',
                                            dataType: 'json',
                                            type: 'get',
                                            async: false,
                                            success: function (data) {
                                                //console.log(data.data);
                                                feeSel = '<select name="statusFee" lay-filter="stateSelectFee" lay-verify="required" id="selectTestFee" data-state="' + d.status + '" data-value="' + d.id + '" >';
                                                $.each(data.data, function (index, val) {
                                                    feeSel = feeSel + '<option value="'+val.feeTypeId+'">' + val.feeTypeName + '</option>'
                                                });
                                                feeSel = feeSel + '   </select>';
                                            }
                                        });
                                        return feeSel;
                                    }else {
                                        return feeSel;
                                    }
                                }
                            },
                            {field:'taxRate',title:'税率',align: 'center', width: 155,
                                templet:function (d) {
                                    return '<select name="statusTaxRate" lay-filter="stateSelectTaxRate" lay-verify="required" id="selectTestTaxRate" data-state="' + d.status + '" data-value="' + d.id + '" >'+
                                        '<option value="0.00">0.00</option><option value="0.03">0.03</option><option value="0.06">0.06</option>'+
                                        '<option value="0.09">0.09</option><option value="0.12">0.12</option><option value="0.15">0.15</option>'+
                                        '</select>';
                                }
                            },
                            {field:'amountReceivable',title:'应收金额',align: 'center', width: 180, edit: 'text'},
                            {field:'taxes',title:'税金',align: 'center', width: 180},
                            {field:'income',title:'收入',align: 'center', width: 180},
                            {title: '操作', width: 120, toolbar: '#barDemoFee', align: "center"}
                        ]
                    ]
                });



                $.ajax({
                    type: "POST",
                    url: "/planOrder/popups",
                    data: {
                        sendArea:data.sendArea,
                        putArea:data.putArea
                    },
                    dataType: "json",
                    success: function (result) {

                        $("#area").empty();
                        $("#purpose").empty();

                        for (var i = 0; i < result.start.length; i++) {
                            $("#area").append(new Option(result.start[i].siteName,result.start[i].siteId))
                        }
                        for (var j = 0; j < result.purpose.length; j++) {
                            $("#purpose").append(new Option(result.purpose[j].siteName,result.purpose[j].siteId))
                        }
                        form.render('select');//刷新下拉框组件
                    }
                });
                //多窗口模式，层叠置顶
                layer.open({
                    type: 1 //此处以iframe举例
                    ,title: '保存订单'
                    ,area: ['1000px', '600px']
                    ,content: $("#tan")//'//layer.layui.com/test/settop.html'
                    ,btn: ['保存','关闭'] //只是为了演示
                    ,no: function(){
                        layer.closeAll();
                    },yes: function (index, layero) {
                        if($("#courierOdd").val() == null){
                            layer.open({
                                title: '提示'
                                ,icon:5
                                ,content: '请获取面单号'
                            });
                        }else{
                            var popups1 = table.cache['popups1'];
                            var popups2 = table.cache['popups2'];

                            //获得弹出层iframe
                            /*var res = window["layui-layer-iframe" + index];
                            //获得iframe，我使用的非模块化直接可以获得iframe中的table*/
                            $.ajax({
                                type:'post',
                                url:'/admin/order/addOrder',
                                data:{
                                    beginBranch:$("#area option:selected").val(),
                                    endBranch:$("#purpose option:selected").val(),
                                    cargoJson:JSON.stringify(popups1),
                                    costJson:JSON.stringify(popups2),
                                    courierOdd:$("#courierOdd").val(),
                                    planOrder:JSON.stringify(obj.data)
                                },
                                dataType:'json',
                                success: function (data) {
                                    $("#courierOdd").val();
                                    $("#area").empty();
                                    $("#purpose").empty();
                                    var tableDate =table.cache['currentTableId'];
                                    table.reload('currentTableId',{url: '/admin/planOrder/findAllPlanOrder'});
                                    layer.closeAll();

                                }
                            })
                        }
                    }
                });

            }else if(obj.event === 'not'){
                $.ajax({
                    type:"GET",
                    url:"/admin/order/getGoodsIssueType",
                    dataType:"JSON",
                    success:function (data) {
                        $("#abnormals").empty();
                        data = data.data;
                        for(var i=0;i<data.length;i++){
                            $("#abnormals").append(new Option(data[i].goodsIssueTypeName,data[i].goodsIssueTypeId));
                        }
                        form.render();
                    }
                });
                layer.open({
                    type: 1 //此处以iframe举例
                    ,title: '异常订单'
                    ,area: ['500px', '310px']
                    ,content: $("#yichang")//'//layer.layui.com/test/settop.html'
                    ,btn: ['确定','关闭'] //只是为了演示
                    ,yes:function (index, layero) {
                        $.ajax({
                            type:"post",
                            url:"/admin/abnormal/addAbnormal",
                            data:{
                                goodsIssueTypeId:$("#abnormals option:selected").val(),
                                remark:$("#desc").val(),
                                planOrderOdd:data.recordedNumber
                            },
                            dataType:"json",
                            success:function (data) {
                                var tableData = table.cache['currentTableId'];
                                table.reload('currentTableId',{data : tableData});
                                layer.closeAll();
                            }
                        });
                    },
                    no:function () {
                        layer.closeAll();
                    }
                });
            }else if(obj.event === 'update'){
                /*修改预录单*/
                layer.open({
                    type: 1
                    , title: '修改预录单'
                    , area: ['1000px', '500px']
                    , content:$("#addPlanOrder")
                    , btn: ['修改', '关闭'], //只是为了演示
                    success:function (res) {
                        layarea.render({
                            elem: '#area-picker'
                        });
                        $.ajax({
                            url: '/admin/planOrder/findAllPlanOrder',
                            dataType: 'json',
                            type: 'get',
                            data:{
                                planOdd:data.recordedNumber
                            },
                            success:function (data) {

                                var a = data.data[0].makeCargoMethod;
                                var sendAddress = (data.data[0].sendArea).split("-");

                                console.log(sendAddress[1]+"|"+sendAddress[2]);
                                $("#planOrderOdd").val(data.data[0].recordedNumber);
                                $("#plandate").val(data.data[0].planOrderTime);
                                //$("#delivery option[value='2']").prop("selected", true);
                                $("#delivery").val(a);

                                var b = "湖南省";
                                $("#province option[value='"+sendAddress[0]+"']").attr("selected", "selected");
                                $("#county option[value='"+sendAddress[1]+"']").attr("selected", "selected");
                                $("#city option[value='"+sendAddress[2]+"']").attr("selected", "selected");

                                $("#detailedArea").val(sendAddress[3]);

                                $("#consigner").val(data.data[0].sendName);
                                $("#consignerPhone").val(data.data[0].sendPhone);

                                $("#addressName").val(data.data[0].putName);
                                $("#addressName").attr('alt',data.data[0].customerId);
                                $("#tel").val(data.data[0].putPhone);
                                $("#address").val(data.data[0].putArea+'/'+data.data[0].putAddress);

                                if(data.data[0].customerId === 0){
                                    $("#customerId").css("display",'none');
                                }
                                form.render('select');
                            }
                        });
                        form.render(); //更新全部
                    },
                    yes:function (index) {



                        var sendArea = $("#province").val()+'-'+$("#city").val()+'-'+$("#county").val();
                        alert(sendArea);
                        $.ajax({
                            type:"Post",
                            dataType:"json",
                            url:'/admin/planOrder/updatePlanOrder',
                            data:{
                                recordedNumber:$("#planOrderOdd").val(),
                                makeMethod:$("#delivery").val(),
                                sendArea:sendArea,
                                sendAddress:$("#detailedArea").val(),
                                sendName: $("#consigner").val(),
                                sendPhone:$("#consignerPhone").val(),
                                putName:$("#addressName").val(),
                                putPhone: $("#tel").val(),
                                putArea: $("#address").val()
                            },
                            success:function (data) {

                                layer.closeAll();
                            }
                        });
                    }
                });

                var areaData;
                table.on('row(addressTableFilter)',function (data) {
                    areaData = data.data;
                });

                //选择收货地址
                $("#updateArea").click(function () {
                    var userId = $("#addressName").attr("alt");
                    var index = layer.open({
                        type: 1
                        , title: '收货地址'
                        , area: ['800px', '400px']
                        , content:$("#userAddress")
                        , btn: ['确定', '关闭'] //只是为了演示
                        ,success:function(){
                            table.render({
                                elem: '#addressTableFilter',
                                url: '/admin/prople/selectAllCustomerAddressByUserId/'+userId,
                                toolbar: '#toolbarDemo',
                                defaultToolbar: [''],
                                cols: [
                                    [
                                        {type:'radio', width: 50,fixed: 'left'},
                                        {field: 'userName', width: 80, title: '用户名'},
                                        {field: 'name', width: 100, title: '收货人', sort: true},
                                        {field: 'tel', width: 120, title: '联系电话'},
                                        {field: 'detailedAddress', title: '详细地址', Width: 120,align:'center'},
                                        {field: 'area', minWidth: 160, title: '所属区域',align:'center'}
                                    ]
                                ],
                                limits: [10, 15, 20, 25, 50, 100],
                                limit: 15,
                                page: true,
                                skin: 'line'
                            });
                        },
                        yes:function () {
                            console.log(areaData);
                            $("#addressName").val(areaData.name);
                            $("#tel").val(areaData.tel);
                            $("#address").val(areaData.area+areaData.detailedAddress);
                            layer.close(index);
                        }
                    });
                });

                //修改详细地址
                $("#updateArea2").click(function () {
                    layer.open({
                        type: 1
                        , title: '百度地图'
                        , area: ['600px', '600px']
                        , content:$("#map")
                        , btn: ['确定', '关闭'] //只是为了演示
                    });
                })
            }else if(obj.event === 'delete'){
                $.ajax({
                    dataType:'json',
                    type:'post',
                    url:'/admin/planOrder/deletePlanOrder',
                    data:{
                        planOrderOdd:data.recordedNumber
                    },
                    success:function (data) {
                        var tableData = table.cache['currentTableId'];
                        table.reload('currentTableId',{data : tableData});
                    }
                })
            }
        });

    });


</script>

<form class="layui-form" action="" style="display:none" id="tan">
    <p style="height: 20px"></p>
    <div class="layui-form-item">
        <label class="layui-form-label">起始网点</label>
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" id="area" lay-filter="area">
            </select>
        </div>
        <label class="layui-form-label">快递单号</label>
        <div class="layui-input-inline">
            <input type="text" name="courierOdd" id="courierOdd" lay-verify="title" autocomplete="off" class="layui-input" readonly="true">
        </div>
        <label class="layui-form-label">目的网点</label>
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" lay-search="" id="purpose">
            </select>
        </div>
    </div>
    <hr/>

    <div class="layui-form">
        <h3>货品明细:</h3>
        <table class="layui-hide" id="popups1" lay-filter="popups1"></table>
    </div>
    <hr/>

    <div class="layui-form">
        <h3>费用明细</h3>
        <table class="layui-hide" id="popups2" lay-filter="popups2"></table>
    </div>
</form>

<form class="layui-form" action="" style="display:none" id="yichang">
<div class="layui-form-item">
    <p style="height: 20px"></p>
    <div class="layui-form-item">
        <label class="layui-form-label">异常原因</label>
        <div class="layui-input-inline">
            <select name="abnormals" lay-verify="required" id="abnormals" lay-filter="abnormals">
            </select>
        </div>

    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" name="desc" rows="3" cols="10" id="desc"></textarea>
        </div>
    </div>
</div>
</form>

</body>

</html>
